import Drawer from "./components/Drawer";
import DrawerItem from "./components/Drawer-item";
import drawerStore from "./store/drawer";

const components = [Drawer, DrawerItem];

// 这一步判断window.Vue是否存在，因为直接引用vue.min.js， 它会把Vue绑到Window上，我们直接引用打包好的js才能正常跑起来。
if (typeof window !== "undefined" && window.Vue) {
  window.Vue.component("v-drawer", components);
}

const install = function(Vue, opts = {}) {
  if (!opts.store) {
    console.log("Please provide a store!");
  }

  components.map(component => {
    Vue.component(component.name, component);
  });

  // 动态注册store
  opts.store.registerModule("drawer", drawerStore);
};

if (typeof window !== "undefined" && window.Vue) {
  install(window.Vue);
}

export default {
  install,
  Drawer,
  DrawerItem
};
